<?php //echo $this->Html->script('jquery-migrate-1.2.1.min',array('inline'=>false))?>
<?php //echo $this->Html->script('jquery.jqzoom.min',array('inline'=>false))?>
<?php //echo $this->Html->css('jquery.jqzoom','stylesheet',array('inline'=>false))?>
<style>	
	.zoom {
		display:inline-block;
		position: relative;
	}
	.zoom img {
		display: block;
	}
	.zoom img::selection { background-color: transparent; }	
</style>
<?php echo $this->Html->script('jquery.zoom-min',array('inline'=>true))?>
<?php echo $this->Html->script('cloudzoomn - min',array('inline'=>true))?>
<?php echo $this->Html->css('cloudzoom','stylesheet',array('inline'=>false))?>
<script language='javascript' type='text/javascript'>
$().ready(function(){
	 CloudZoom.quickStart();
	//$('#ex1').zoom();
	//$('#ex1').zoom({ on:'grab' });
	//$('#ex1').zoom({ on:'click' });			 
	//$('#ex1').zoom({ on:'toggle' });			 
});
</script>
<?php $this->Html->addCrumb('Sản phẩm','view')?>

<?php echo $this->element('left_menu',array('categories'=>$categories,'brand'=>$rs['Brand']['name']))?>
<div class="mainColumn">
<?php if(isset($rs)):?>
<?php $this->Html->addCrumb($rs['Product']['name'])?>
<div class="productDetail">
	<div class="productDetailImage" style="position: relative;">		
		<!--<a class="jqzoom" href="/upload_files/<?php echo $rs['Product']['photo_dir'].'/'.$rs['Product']['photo']?>" title="<?php echo $rs['Product']['name']?>">
			<img alt="<?php echo $rs['Product']['name']?>" src="/upload_files/<?php echo $rs['Product']['photo_dir'].'/big_'.$rs['Product']['photo']?>" title="">
		</a>-->
		<!--<span class='zoom' id='ex1'>
			<img width='330' alt="<?php echo $rs['Product']['name']?>" src="/upload_files/<?php echo $rs['Product']['photo_dir'].'/'.$rs['Product']['photo']?>" title="<?php echo $rs['Product']['name']?>">
		</span>-->
		<a href="/upload_files/<?php echo $rs['Product']['photo_dir'].'/'.$rs['Product']['photo']?>" title="<?php echo $rs['Product']['name']?>">
			<img class='cloudzoom' data-cloudzoom='zoomFlyOut:false' alt="<?php echo $rs['Product']['name']?>" src="/upload_files/<?php echo $rs['Product']['photo_dir'].'/big_'.$rs['Product']['photo']?>" title="">
		</a>		
	</div>	
	<div class="productDetailInfo">
		<h3><?php echo $rs['Product']['name'] ?></h3>
		<strong>Mã SP</strong>: <?php echo $rs['Product']['product_code']?><br>
		<strong>Nhà sản xuất:</strong>: <?php echo $rs['Brand']['name']?><br>
		<strong>Xuất xứ</strong>: <?php echo $rs['Product']['source']?><br>
		<strong>Chi tiết sản phẩm</strong>:<br/><?php echo nl2br($rs['Product']['description'])?><br>
		<strong>Số lượt xem</strong>: <?php echo $rs['Product']['views']?><br>
		<strong>Kích thước</strong>:
		<?php
		$oos = false;
		foreach($stocks as $item){
			echo $item['Size']['name'].'; ';
			//Check as if there is a stock of product
			if($oos == false && $item['Stock']['amount'] > 0){
				$oos = true;
			}
		}
		?>
		<br>
		<strong>Giá:</strong><span class="productListItemPrice"> <?php echo number_format($rs['Product']['price'])?> VND</span>

		<?php if($oos):?>
		<?php echo $this->Form->create('Product',array('url'=>array('action'=>'add','controller'=>'carts'),'type'=>'post'))?>
		<?php echo $this->Form->hidden('id',array('value'=>$rs['Product']['id']))?>
		<?php echo $this->Form->hidden('name',array('value'=>$rs['Product']['name']))?>		
		<!-- selectbox size - show only size in stock -->
		<select name='sizeval' id='sizeval' class="productDetailForm">
		<option value=''>Kích thước</option>
		<?php foreach($stocks as $item):?>
		<option value='<?php echo $item['Size']['name']?>'><?php echo $item['Size']['name']?></option>
		<?php endforeach;?>
		</select>
		
		<select class="productDetailForm" name="quantityval" id="quantityval">
		<option value="0">Số lượng</option>
		<option value="1">1</option>
		<option value="2">2</option>
		<option value="3">3</option>
		<option value="4">4</option>
		<option value="5">5</option>
		</select>
		
		<div style="color:red;" id="product-status"></div>
		
		<div class="productDetailButton">
			<?php echo $this->Form->submit('/img/button_addBag.jpg')?>			
		</div>		
		<?php echo $this->Form->end()?>
		<?php else:?>
		<br/>Hết hàng
		<?php endif;?>
	</div>
</div>
<?php endif;?>
	
<!--Related products-->	
<?php if($same_cat):?>
<div class="productList">
	<div class="productListMatching">
		<h5><strong>Sản phẩm cùng bộ sưu tập</strong></h5>
		<?php
		$i = 0;
		foreach($same_cat as $item):
		$i++;
		?>
		<div class="productListItem<?php if($i % 4 == 0) echo ' productListItemEnd'?>">
			<?php
			$url = '/san-pham/'.$item['Product']['slug'];
			$image_path = '/upload_files/'.$item['Product']['photo_dir'].'/'.$item['Product']['photo'];
			if(!file_exists(WWW_ROOT.$image_path)){
				$image_path = 'no_image.jpg';
			}
			echo $this->Html->image($image_path,array('alt'=>$item['Product']['name'],'title'=>$item['Product']['name'],'url'=>$url,'width'=>140));
			?>		
			<div><strong><?php echo $item['Product']['name']?></strong></div>
			<strong>Mã SP:</strong> <?php echo $item['Product']['product_code']?><br>
			<strong>Giá:</strong> <span class="productListItemPrice"><?php echo number_format($item['Product']['price'])?> VND</span>
		</div>
		<?php endforeach;?>
	</div>
</div>
<?php endif;?>

</div>
<script type="text/javascript">
$().ready(function() {	
	//$('.jqzoom').jqzoom({
		//zoomType: 'innerzoom',		
		//preloadImages: true,
		//alwaysOn:false
    //});
	$('#ProductDetailForm').submit(function(){
		if($('#sizeval').val() == '' || $('#quantityval').val() == ''){
			alert('Vui lòng chọn kích thước và số lượng');
			return false;
		}
		return true;
	});
});
</script>